package ui.swing.laf;

import java.awt.Component;
import java.awt.Font;
import java.util.Enumeration;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class LookAndFeelUtils {

	private LookAndFeelUtils() {
	}

	static final void changeLookAndFeel(final String lafClassName, final Font font, final Component comp) throws Exception {
		if (font != null) {
			Enumeration keys = UIManager.getLookAndFeelDefaults().keys();
			while (keys.hasMoreElements()) {
				Object key = keys.nextElement();
				if (UIManager.get(key) instanceof Font) {
					UIManager.put(key, font);
				}
			}
		}
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				try {
					UIManager.setLookAndFeel(lafClassName);
				} catch (Exception e) {
					e.printStackTrace();
				}

				if (comp != null) {
					SwingUtilities.updateComponentTreeUI(comp);
				}
			}
		});

	}

}
